﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.Runtime.InteropServices;

namespace Reticulum.User
{
    public partial class File_renaming_properties : Form
    {
        public File_renaming_properties()
        {
            InitializeComponent();
        }
        public static string sql = null;
        public static string fliename = null;
        public static string flieLength = null;
        public static string flieType = null;
        public static string flieTime = null;
        string type;
        private void File_renaming_properties_Load(object sender, EventArgs e)
        {
            sql = string.Format("select FlieName,FlieLength,FlieSuffix,FlieGetTime from FlieInfo where original_File_name='{0}'and UserID='{1}'", Client.choice_term,ThisMyInfo.UserID);
            SqlDataReader reader=DBHelps.Select(sql);
            while (reader.Read())
            {
                fliename = reader["FlieName"].ToString();
                flieLength= reader["FlieLength"].ToString();
                flieType= reader["FlieSuffix"].ToString();
                flieTime = reader["FlieGetTime"].ToString();
            }
            reader.Close();
            DBHelps.reader = null;
            type = flieType;
            if (flieType==".jpg"|| flieType == ".png")
            {
                flieType = "图片";
            }
            else if (flieType == ".mp3")
            {
                flieType = "音乐";
            }
            else if (flieType == ".mp4")
            {
                flieType = "视频";
            }
            else if (flieType == ".docx")
            {
                flieType = "文档";
            }
            else if (flieType == ".zip"|| flieType == ".rar")
            {
                flieType = "压缩包";
            }
            else
            {
                flieType = "其他";
            }
            this.textBox1.Text =fliename;
            this.textBox2.Text = flieLength + "kb";
            this.textBox3.Text = flieType;
            this.textBox4.Text = ThisMyInfo.UserAccount;
            this.textBox5.Text = flieTime;
            if (Client.CmmandShuxing==1)
            {
                this.button3.Visible = false;
                this.label4.Visible = false;
                this.label5.Visible = false;
                this.textBox4.Visible = false;
                this.textBox5.Visible = false;
            }
            if (Client.CmmandShuxing == 2)
            {
                this.textBox1.ReadOnly = true;
                this.button1.Visible = false;
                this.button2.Visible = false;
                this.button3.Visible = true;
                this.textBox4.Visible = true;
                this.textBox5.Visible = true;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            
                this.Close();
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            sql = string.Format("update FlieInfo set FlieName='{0}',original_File_name=('{1}'+'{2}') where original_File_name='{3}' and UserID='{4}'", this.textBox1.Text, textBox1.Text, type, Client.choice_term,ThisMyInfo.UserID);
            bool result=DBHelps.Command(sql);
            if (result)
            {
                DialogResult result1 = MessageBox.Show("文件重命名成功"+"\n\r"+"是否退出重命名？","退出",MessageBoxButtons.YesNo);
                if (result1 == DialogResult.Yes)
                {
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("修改失败");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //无边框拖动窗体-----------------------------------------------
        [DllImport("user32.dll")]//*********************拖动无窗体的控件  需要引用
        public static extern bool ReleaseCapture();
        [DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
        public const int W = 0x0112;
        public const int S = 0xF010;
        public const int H = 0x0002;
        private void File_renaming_properties_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(this.Handle, W, S + H, 0);//*********************调用移动无窗体控件函数
        }
    }
}
